<%-- 
    Document   : produccion
    Created on : 03-nov-2011, 23:31:40
    Author     : Leonel
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link href="css/tablecloth.css" rel="stylesheet" type="text/css" media="screen" />
        <script type="text/javascript" src="js/tablecloth.js"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
        <link media="screen" rel="stylesheet" href="css/colorbox.css" />
	<script src="js/jquery.colorbox.js"></script>
        <script>
            //            
            //            $(document).ready(function() {
            //                $("#formBusqueda").ajaxForm({
            //                    type: "POST",
            //                    target: "#resultados",
            //                    url: "TablaServlet"
            //                }); 
            //                $("#formSobon").ajaxForm({
            //                    type: "POST",
            //                    target: "#resultados"
            //                });
            //            });
            
            
            $(document).ready(function () {
                $('#costos').fadeIn(1200);
                
                $(".verResultados").colorbox({width:"50%", inline:true, href:"#resultados"});
                
            });
            function validar(e) { // 1
                tecla = (document.all) ? e.keyCode : e.which;
                if (tecla == 8)
                    return true; //Tecla de retroceso (para poder borrar)
                patron = /\d/;
                te = String.fromCharCode(tecla);
                return patron.test(te);
            }
            
            function NumCheck(e, field) { 
                key = e.keyCode ? e.keyCode : e.which 
                // backspace 
                if (key == 8) return true 
                // 0-9 
                if (key > 47 && key < 58) { 
                    if (field.value == "") return true 
                    regexp = /.[0-9]{5}$/ 
                    return !(regexp.test(field.value)) 
                } 
                // . 
                if (key == 46) { 
                    if (field.value == "") return false 
                    regexp = /^[0-9]+$/ 
                    return regexp.test(field.value) 
                } 
                // other key 
                return false 
                
            } 
            
        </script>
        <style>
            td, th, input {
                font-family: Segoe ui, sans-serif;
                font-size: 9pt;
                text-align: center;
            }
            input[type=text]{
                width: 40px;
            }
                
            
        </style>
        
    </head>
    <body>
        
        <h1>Tabla de Resultados</h1>
        
        <% //Parámetros Recibidos por el Servlet 
            Integer num = (Integer)request.getAttribute("numero");           
            if(num==null){
                num=1;
            }
            Integer produccion = (Integer)request.getAttribute("produccion");
            String inventario[] = (String[])request.getAttribute("inventario");           
            
            String aux[]= (String[])request.getAttribute("cantidades");
            String initInvIni= (String)request.getAttribute("txtInvIni");
            String initInvFin= (String)request.getAttribute("txtInvFin");
            String initCostoInv= (String)request.getAttribute("txtCostoInv");
            String initCostoBO= (String)request.getAttribute("txtCostoBO");
            String initCostoContr= (String)request.getAttribute("txtCostoContr");
            String initCostoDesp= (String)request.getAttribute("txtCostoDesp");
            String initSalario= (String)request.getAttribute("txtSalario");
            String initRecargo= (String)request.getAttribute("txtRecargo");
            String initStock= (String)request.getAttribute("txtStock");
            String empleados[] = (String[])request.getAttribute("empleados");
            String capacidad = (String)request.getAttribute("txtcapacidad");
            String contrataciones[] = (String[])request.getAttribute("contrataciones");
            String despidos[] =(String[])request.getAttribute("despidos");
            String suplementos[] = (String[])request.getAttribute("suplementos");
            String tablaCostos = (String)request.getAttribute("tablaCostos");
            
            String EmpIni="";
            if(capacidad==null){
                capacidad="";
            }
            if(tablaCostos==null){
                tablaCostos="";
            }
            if(empleados==null){
                EmpIni="";
            }else{
                EmpIni = empleados[0];
            }
            
            if(initInvFin==null){
                initInvFin="";
            }
            if(initInvIni==null){
                initInvIni="";
            }
            if(initCostoInv==null){
                initCostoInv="";
            }
            if(initCostoBO==null){
                initCostoBO="";
            }
            if(initCostoContr==null){
                initCostoContr="";
            }
            if(initCostoDesp==null){
                initCostoDesp="";
            }
            if(initSalario==null){
                initSalario="";
            }
            if(initRecargo==null){
                initRecargo="";
            }
            if(initStock==null){
                initStock="";
            }
        %>
        
        <p>
            Ponga la cantidad de meses a operar:
        <form method="post" id="formSobon" action="TablaServlet">
            <input type="text" name="periodos" onkeypress='return validar(event);' required/>
            <input type="submit" value="Aceptar" />
        </form>
    </p>
    <div style="margin:0 auto 0 auto; width: 760px; float:left">
        <form method="post" id="formBusqueda" action="AgregadoServlet">
            <input type="hidden" value="<%=num%>" name="meses"/>
            
            <p>
                <label for="idCapacidad">Capacidad Empleados:</label>
                <input type="text" value="<%=capacidad%>" id="idCapacidad" name="txtcapacidad" onkeypress='return validar(event);' required/> UE
            </p>
            <p>
                Costo Inventario por Mes:&nbsp;
                $<input type="text" value="<%=initCostoInv%>" name="txtCostoInv" onkeypress="return NumCheck(event, this)" required/>
            </p>
            <p>
                Costo de Escasez por Mes:&nbsp;
                $<input type="text" value="<%=initCostoBO%>" name="txtCostoBO"onkeypress="return NumCheck(event, this)" required/>
            </p>
            <p>
                Costo de Contratación por persona:&nbsp;
                $<input type="text" value="<%=initCostoContr%>" name="txtCostoContr" onkeypress="return NumCheck(event, this)" required/>
            </p>
            <p>
                Costo por despido:&nbsp;
                $<input type="text" value="<%=initCostoDesp%>" name="txtCostoDesp" onkeypress="return NumCheck(event, this)" required/>
            </p>
            
            <p>
                Salario&nbsp;
                $<input type="text" value="<%=initSalario%>" name="txtSalario" onkeypress="return NumCheck(event, this)" required/>
            </p>
            
            <p>
                Recargo&nbsp;
                <input type="text" value="<%=initRecargo%>" name="txtRecargo" onkeypress="return NumCheck(event, this)" required/>%
            </p>
            <p>
                Stock por mes&nbsp;
                <input type="text" value="<%=initStock%>" name="txtStock" onkeypress='return validar(event);' required/>
            </p>
            <table cellspacing="0" cellpadding="0">
                <tr>
                    <td>&nbsp;</td>
                    <th>Inicial</th>
                    <% for(int i = 0; i<num; i++) {
                        out.println("<th>Mes "+(i+1)+"</th>");
                    }%>
                    <th>Final</th>
                    
                </tr>
                <tr>
                    <th>Demanda (ue)</th>
                    <td>-</td>
                    
                    <% 
                    String dem[] = new String[num];
                    if (aux==null){
                        for(int k=0; k<num; k++){
                            dem[k]="";
                        }
                    }else{
                    
                        for(int k=0; k<aux.length; k++){
                            dem[k]=aux[k];
                        }
                    }               
                    for(int i = 0; i<num; i++) {
                        out.println("<td><input type='text' size='3' id='cantidad"+(i+1)+"' value='"+dem[i]+"' name='cantidades' onkeypress='return validar(event);' required/></td>");
                    }%>
                    <td>-</td>
                </tr>
                <tr>
                    <th>Producción</th>
                    <td>-</td>
                    
                    <% 
                    String resdemanda = "-";
                    if(produccion==null){
                        resdemanda = "-";
                    }else{
                        resdemanda = String.valueOf(produccion);
                    }    
                    for(int i = 0; i<num; i++) {
                        out.println("<td>"+resdemanda+"</td>");
                    }%>
                    <td>-</td>
                </tr>			
                <tr>
                    <th>Inventario</th>
                    <td><input type="text" size="3" value="<%=initInvIni%>" name="txtInvIni" onkeypress='return validar(event);' required/></td>
                    
                    <% 
                    String inv[] = new String[num];
                    String bginv="";
                    if (inventario==null){
                        for(int k=0; k<num; k++){
                            inv[k]="-";
                        }
                    }else{                  
                        for(int x=0; x<num; x++){
                            inv[x]=inventario[x+1];
                                                    
                        }
                    }
                    for(int i = 0; i<num; i++) {
                        try{
                            if(inventario!=null){
                        if(Integer.parseInt(inv[i])<0){
                                bginv="style='background-color:#FF6666;'";                               
                            }else{
                                if(Integer.parseInt(inv[i])==0){
                                    bginv="style='background-color:#FFFF99;'";
                                }else{
                                    bginv="";
                                }
                                
                            }
                                               }
                        }catch(Exception e){
                            out.println("<script>alert('"+e.getMessage()+"');</script>");
                        }                                            
                            out.println("<td "+bginv+">"+inv[i]+"</td>");
                        }
                    %>
                    <td><input type="text" size="3" value="<%=initInvFin%>" name="txtInvFin" onkeypress='return validar(event);' required/></td>
                </tr>			
                <tr>
                    <th>Empleados</th>
                    <td><input type="text" value="<%=EmpIni%>" size="3" name="txtEmpIni" onkeypress='return validar(event);' required/></td>
                        <% 
                        String resempleados[] = new String [num];
                        for(int i=0; i<num;i++){
                            if(produccion==null){
                                resempleados[i] = "-";
                            }else{
                                resempleados[i] = empleados[i+1];
                            }
                        }
                        for(int i = 0; i<num; i++) {
                            out.println("<td>"+resempleados[i]+"</td>");
                        }
                        %>
                    <td>-</td>
                </tr>			
                <tr>
                    <th>Contrataciones</th>
                    <td>-</td>
                    <% 
                   // String rescontrataciones[] = new String [num];
                        for(int i=0; i<num;i++){
                            if(contrataciones==null){
                                //rescontrataciones[i] = "-";
                                out.println("<td>-</td>");
                            }else{
                                //rescontrataciones[i] = contrataciones[i];
                                out.println("<td>"+contrataciones[i]+"</td>");
                            }
                        }
                    
                        //for(int i = 0; i<num; i++) {
                         //out.println("<td>"+contrataciones[i]+"</td>");
                     //}%>
                    <td>-</td>
                </tr>
                <tr>
                    <th>Despidos</th>
                    <td>-</td>
                    <% for(int i=0; i<num;i++){
                            if(despidos==null){
                                //rescontrataciones[i] = "-";
                                out.println("<td>-</td>");
                            }else{
                                //rescontrataciones[i] = contrataciones[i];
                                out.println("<td>"+despidos[i]+"</td>");
                            }
                        }
                     %>
                    <td>-</td>
                </tr>
                <tr>
                    <th>Suplementos</th>
                    <td>-</td>
                    <% for(int i=0; i<num;i++){
                            if(suplementos==null){
                                //rescontrataciones[i] = "-";
                                out.println("<td>-</td>");
                            }else{
                                //rescontrataciones[i] = contrataciones[i];
                                out.println("<td>"+suplementos[i]+"</td>");
                            }
                        }
 
 %>
                    <td>-</td>
                </tr>
                
            </table>
            <input type="submit" value="Procesar" />
        </form>
                    <%=tablaCostos %>
    </div>
                
</body>
</html>
